//==================================================================
//	Copyright (C) 2006  Davide Pasca
//
//	This program is free software; you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation; either version 2 of the License, or
//	(at your option) any later version.
//
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with this program; if not, write to the Free Software
//	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//==================================================================
///
///
///
///
//==================================================================

#include "StdTypes.hlsl"

//==================================================================
uniform sampler2D	_color_texmap		: register(s0);
uniform float3		_fog_col			: register(c0);
uniform float4		_specular_col_pow	: register(c1);

//==================================================================
///
//==================================================================
float4 Std_Generic_PS( const VSOUT_PTC input, bool has_tex, bool has_nor ) : COLOR
{
	float4	out_col;

	if ( has_tex )
		out_col = tex2D( _color_texmap, input._tex ) * input._col;
	else
		out_col = input._col;

	if ( has_nor )
	{
		float3	nor		= normalize( input._nor );
		float3	ldir	= normalize( input._light_pos );
		float3	vdir	= normalize( input._viewdir );

//		float3	diff_c	= saturate( dot( nor, ldir ) ) * float3( 0.0, 0.0, 0.7 );
		float	sshadow	= saturate( 4 * dot( nor, ldir ) );

		// R = 2 * (N.L) * N ? L
		//(ldir + vdir)  
		float3	refl	= reflect( ldir, nor );
		float3	spec_c	= _specular_col_pow.xyz * pow( dot( refl, vdir ), _specular_col_pow.w ); // R.V^n

		out_col.xyz += saturate( sshadow * spec_c );
	}

	out_col.rgb = lerp( _fog_col.rgb, out_col.rgb, input._fog_coe.x );

	return out_col;
}

//==================================================================
float4 Std_T0_N0_PS( const VSOUT_PTC input ) : COLOR	{ return Std_Generic_PS( input, false, false ); }
float4 Std_T0_N1_PS( const VSOUT_PTC input ) : COLOR	{ return Std_Generic_PS( input, false, true ); }
float4 Std_T1_N0_PS( const VSOUT_PTC input ) : COLOR	{ return Std_Generic_PS( input, true,  false ); }
float4 Std_T1_N1_PS( const VSOUT_PTC input ) : COLOR	{ return Std_Generic_PS( input, true,  true ); }
